<?php
/**
 * Created by PhpStorm.
 * User: nightelf
 * Date: 2020/1/10
 * Time: 9:33
 */

namespace App\Http\Model;


use Illuminate\Support\Facades\DB;

class UnitModel
{
    const TABLE = 'unit';

    /**
     * 计量单位列表
     * @return mixed
     */
    public function lists()
    {
        return DB::table(self::TABLE)->get()->toArray();
    }

    /**
     * @param array $data
     * @return array
     */
    public function info($data = [])
    {
        $result = DB::table(self::TABLE)->where($data)->first();
        return empty($result) ? [] : get_object_vars($result);
    }

    /**
     * @param array $data
     * @return mixed
     */
    public function insert(Array $data)
    {
        $insertData = [
            'name' => $data['name'],
            'shortname' => $data['shortname'],
            'createTime' => date('Y-m-d H:i:s', time()),
        ];
        return DB::table(self::TABLE)->insertGetId($insertData);
    }

    /**
     * @param array $where
     * @param array $data
     * @return mixed
     */
    public function update(array $where ,array $data)
    {
        return DB::table(self::TABLE)->where($where)->update($data);
    }
}